home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
SETUP
/
US
/
CBUILDER
/
DATA.Z
/
BCD.H
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-13
|
11KB
|
408 lines
/* bcd.h
BCD Number Library - Include File
class bcd: declarations for decimal numbers.
*/
/*
* C/C++ Run Time Library - Version 8.0
*
* Copyright (c) 1987, 1997 by Borland International
* All Rights Reserved.
*
*/
/* $Revision: 8.3 $ */
#ifndef __cplusplus
#error Must use C++ for the type bcd.
#endif
#if !defined(__BCD_H)
#define __BCD_H
#if !defined(___DEFS_H)
#include <_defs.h>
#endif
#if !defined(__MATH_H)
#include <math.h>
#endif
#if !defined(__IOSTREAM_H)
#include <iostream.h>
#endif
#if !defined(RC_INVOKED)
#pragma pack(push, 1)
#if defined(__BCOPT__)
#if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
#pragma option -po- // disable Object data calling convention
#endif
#endif
#pragma option -Vo-
#if defined(__STDC__)
#pragma warn -nak
#endif
#endif /* !RC_INVOKED */
#define _BcdMaxDecimals 5000
_CLASSDEF(bcd)
class _EXPCLASS bcd {
public:
// constructors
_RTLENTRY bcd();
_RTLENTRY bcd(int x);
_RTLENTRY bcd(unsigned int x);
_RTLENTRY bcd(long x);
_RTLENTRY bcd(unsigned long x);
_RTLENTRY bcd(double x, int decimals = _BcdMaxDecimals);
_RTLENTRY bcd(long double x, int decimals = _BcdMaxDecimals);
// bcd manipulations
friend long double _RTLENTRY real(const bcd _FAR &); // Return the real part
// Overloaded ANSI C math functions
friend bcd _RTLENTRY _EXPFUNC abs(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC acos(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC asin(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC atan(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC cos(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC cosh(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC exp(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC log(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC log10(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC pow(const bcd _FAR & base, const bcd _FAR & expon);
friend bcd _RTLENTRY _EXPFUNC sin(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC sinh(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC sqrt(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC tan(const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC tanh(const bcd _FAR &);
// Binary Operator Functions
friend bcd _RTLENTRY _EXPFUNC operator+(const bcd _FAR &, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator+(long double, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator+(const bcd _FAR &, long double);
friend bcd _RTLENTRY _EXPFUNC operator-(const bcd _FAR &, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator-(long double, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator-(const bcd _FAR &, long double);
friend bcd _RTLENTRY _EXPFUNC operator*(const bcd _FAR &, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator*(const bcd _FAR &, long double);
friend bcd _RTLENTRY _EXPFUNC operator*(long double, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator/(const bcd _FAR &, const bcd _FAR &);
friend bcd _RTLENTRY _EXPFUNC operator/(const bcd _FAR &, long double);
friend bcd _RTLENTRY _EXPFUNC operator/(long double, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator==(const bcd _FAR &, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator!=(const bcd _FAR &, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator>=(const bcd _FAR &, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator<=(const bcd _FAR &, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator>(const bcd _FAR &, const bcd _FAR &);
friend int _RTLENTRY _EXPFUNC operator<(const bcd _FAR &, const bcd _FAR &);
bcd _FAR & _RTLENTRY operator+=(const bcd _FAR &);
bcd _FAR & _RTLENTRY operator+=(long double);
bcd _FAR & _RTLENTRY operator-=(const bcd _FAR &);
bcd _FAR & _RTLENTRY operator-=(long double);
bcd _FAR & _RTLENTRY operator*=(const bcd _FAR &);
bcd _FAR & _RTLENTRY operator*=(long double);
bcd _FAR & _RTLENTRY operator/=(const bcd _FAR &);
bcd _FAR & _RTLENTRY operator/=(long double);
bcd _RTLENTRY operator+();
bcd _RTLENTRY operator-();
// Implementation
private:
long mantissa[2];
int expo;
};
// const bcd _bcd_zero(0);
enum _bcdexpo {
_ExpoZero,
_ExpoInf,
_ExpoNan
};
extern "C"
{
#if defined(__FLAT__)
long double _RTLENTRY _EXPFUNC __bcd_tobinary (const bcd *p);
void _RTLENTRY _EXPFUNC __bcd_todecimal(long double x, int decimals, bcd *p);
long double _RTLENTRY _EXPFUNC __bcd_log10 (const bcd *p);
void _RTLENTRY _EXPFUNC __bcd_pow10 (int n, bcd *p);
#else
long double __pascal _EXPFUNC __bcd_tobinary(const bcd __far *p);
void __pascal _EXPFUNC __bcd_todecimal(long double x, int decimals, bcd __far *p);
long double __pascal _EXPFUNC __bcd_log10(const bcd __far *p);
void __pascal _EXPFUNC __bcd_pow10(int n, bcd __far *p);
#endif
}
inline _RTLENTRY bcd::bcd()
{
/* if you want zero ...
mantissa[0] = 0;
mantissa[1] = 0;
expo = ExpoZero;
*/
}
inline _RTLENTRY bcd::bcd(long double x, int decimals)
{
__bcd_todecimal(x,decimals,this);
}
inline _RTLENTRY bcd::bcd(double x, int decimals)
{
__bcd_todecimal(x,decimals,this);
}
inline _RTLENTRY bcd::bcd(int x)
{
mantissa[0] = x;
mantissa[1] = x >= 0 ? 0 : -1;
expo = 0;
}
inline _RTLENTRY bcd::bcd(unsigned int x)
{
mantissa[0] = x;
mantissa[1] = 0;
expo = 0;
}
inline _RTLENTRY bcd::bcd(long x)
{
mantissa[0] = x;
mantissa[1] = x >= 0 ? 0 : -1;
expo = 0;
}
inline _RTLENTRY bcd::bcd(unsigned long x)
{
mantissa[0] = x;
mantissa[1] = 0;
expo = 0;
}
inline long double _RTLENTRY real(const bcd _FAR &z)
{
return __bcd_tobinary(&z);
}
// Definitions of compound-assignment operator member functions
inline bcd& _RTLENTRY bcd::operator+=(const bcd _FAR &b)
{
__bcd_todecimal(real(*this)+real(b),_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator+=(long double b)
{
__bcd_todecimal(real(*this)+b,_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator-=(const bcd _FAR &b)
{
__bcd_todecimal(real(*this)-real(b),_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator-=(long double b)
{
__bcd_todecimal(real(*this)-b,_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator*=(const bcd _FAR &b)
{
__bcd_todecimal(real(*this)*real(b),_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator*=(long double b)
{
__bcd_todecimal(real(*this)*b,_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator/=(const bcd _FAR &b)
{
__bcd_todecimal(real(*this)/real(b),_BcdMaxDecimals,this);
return *this;
}
inline bcd& _RTLENTRY bcd::operator/=(long double b)
{
__bcd_todecimal(real(*this)/b,_BcdMaxDecimals,this);
return *this;
}
// Definitions of non-member binary operator functions
inline bcd _RTLENTRY operator+(const bcd _FAR &a, const bcd _FAR &b)
{
return bcd(real(a) + real(b));
}
inline bcd _RTLENTRY operator+(long double a, const bcd _FAR &b)
{
return bcd(a + real(b));
}
inline bcd _RTLENTRY operator+(const bcd _FAR &a, long double b)
{
return bcd(real(a) + b);
}
inline bcd _RTLENTRY operator-(const bcd _FAR &a, const bcd _FAR &b)
{
return bcd(real(a) - real(b));
}
inline bcd _RTLENTRY operator-(long double a, const bcd _FAR &b)
{
return bcd(a - real(b));
}
inline bcd _RTLENTRY operator-(const bcd _FAR &a, long double b)
{
return bcd(real(a) - b);
}
inline bcd _RTLENTRY operator*(const bcd _FAR &a, const bcd _FAR &b)
{
return bcd(real(a) * real(b));
}
inline bcd _RTLENTRY operator*(const bcd _FAR &a, long double b)
{
return bcd(real(a) * b);
}
inline bcd _RTLENTRY operator*(